from ftplib import FTP

import logging
logging.basicConfig(level=logging.DEBUG)

def retrieve():
    ftp = FTP('lookas.janmaru.com')
    ftp.login("lookas", "sakool")
    ftp.cwd("mail/new")
    ftp.set_pasv(True)
    x = ftp.nlst()
    ret = []
    for f in x[2:]:
        fi = open(ROOT_DIR + "/mail/" + f, 'w')
        logging.info(fi.name)
        ret.append(fi.name)
        logging.info(ftp.retrlines("RETR " + f, lambda s, w=fi.write: w(s + "\n")))    
        fi.close()
        ftp.delete(f)
    logging.info(ftp.quit())
    return ret
